package task1205.Demo.Demo3;

import task1205.Demo.Demo2.Demo1;
import task1205.Demo.Demo4.CallService;

public class TalkPackage extends SercicePackage implements CallService {
    private int talkTime;
    private int smsCount;

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    @Override
    public void ShowInfo() {
        System.out.println("话痨太长：通话时长为："+this.talkTime+"分钟/月，短信条数为："+this.smsCount+"条/月，资费为："+this.price+"元/月。");
    }

    @Override
    public int call(int minCount, Demo2 demo2) throws Exception {
        int temp = minCount;
        for (int i = 0; i < minCount; i++) {
            if (this.talkTime-demo2.getRealTalkTime()>=1){
                demo2.setRealTalkTime(demo2.getRealTalkTime()+1);
            }else if (demo2.getMoney() >= 0.2){
                demo2.setRealTalkTime(demo2.getRealTalkTime()+1);
                demo2.setMoney(Demo1.sub(demo2.getMoney(),0.2));
                demo2.setConsumAmount(demo2.getConsumAmount()+0.2);
            }else {
                temp = i;
                throw new Exception("本次通话"+i+"分钟，您的余额不足，请充值后在使用");
            }
        }
        return temp;
    }
}
